package com.cater.sys.service.impl;

import java.util.List;
import java.util.Map;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.cater.common.BaseEntity;
import com.cater.common.PageResult;
import com.cater.query.CommonQuery;
import com.cater.sys.dao.AreaDao;
import com.cater.sys.entity.Area;
import com.cater.sys.service.BaseService;

/**
 * @author 作者: sd
 * @date 创建时间：2017年2月28日 下午2:55:21
 * @version 1.0
 */
@Service
public class AreaServiceImpl implements BaseService<Area, CommonQuery, Integer> {

	@Autowired
	private AreaDao dao;

	@Override
	public PageResult<Area> findPageResult(CommonQuery query) {
		PageResult<Area> result = new PageResult<Area>();
		result.setPage(query.getPage());
		result.setPageSize(query.getRows());
		int count = dao.findCount(query);
		int first = (query.getPage() - 1) * query.getRows();
		int max = query.getRows();
		List<Area> list = dao.findList(query, first, max);
		result.setRows(list);
		result.setRecords(count);
		return result;
	}

	@Override
	public List<Area> getAll() {
		return dao.getAll();
	}

	@Override
	public List<Area> getAllCommon(CommonQuery query) {
		return dao.getAllCommon(query);
	}

	@Override
	public int save(Area t) {
		BaseEntity.getCreate(t);
		dao.save(t);
		return t.getId();
	}

	@Override
	public void update(Area t) {
		BaseEntity.getupdate(t);
		dao.update(t);
	}

	@Override
	public void delete(String id) {
		dao.delete(Integer.valueOf(id));

	}

	@Override
	public Area getById(String id) {
		return dao.getById(Integer.valueOf(id));
	}

	public List<Area> getByPid(String fatherId, CommonQuery query) {
		return dao.getBypid(Integer.valueOf(fatherId), query);
	}

	public int getChildCount(String id) {
		return dao.getChildCount(Integer.valueOf(id));
	}

	@Override
	public String saves(Area t) {
		return null;
	}

	public Area getByParent(CommonQuery query) {
		return dao.getByParent(query);
	}

	public List<Area> getByLevelAll(CommonQuery query) {
		return dao.getByLevelAll(query);
	}

	public Area getByName(CommonQuery query) {
		return dao.getByName(query);
	}
	public List<Map<String, Object>> getOtherAll() {
		return dao.getOtherAll();
	}

	public List<Map<String, Object>> getCityAll(Integer codep) {
		return dao.getCityAll(codep);
	}

	public List<Map<String, Object>> getAreaAll(Integer codec) {
		return dao.getAreaAll(codec);
	}

	public String getCitys(String[] cityIds) {
		List<Area> rAreas = dao.getCitys(cityIds);
		String city = "";
		for (Area area : rAreas) {
			city += area.getTitle() + ",";
		}
		return city;
	}
	
	public List<Area> getAllList(CommonQuery query){
		return dao.getAllList(query);
	}

}
